package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.activity.jiuzhou.CrossJiuZhouDeployData;
import com.yanqu.road.entity.activity.jiuzhou.CrossJiuZhouPatronsData;
import com.yanqu.road.entity.activity.jiuzhou.config.JiuZhouRoundConfig;
import com.yanqu.road.entity.activity.jiuzhou.helper.show.*;
import com.yanqu.road.pb.activity.jiuzhou.JiuZhouProto;
import com.yanqu.road.pb.patrons.PatronsProto;

import java.math.BigInteger;
import java.util.Map;

public class JiuZhouPb {

    public static JiuZhouProto.JiuZhouRoundConfigMsg.Builder parseJiuZhouRoundConfigMsg(JiuZhouRoundConfig config) {
        if (config == null) {
            return null;
        }
        JiuZhouProto.JiuZhouRoundConfigMsg.Builder builder = JiuZhouProto.JiuZhouRoundConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setType(config.getType());
        builder.addAllUpRank(config.getUpRank());
        builder.setScore(config.getScore());
        builder.setTime(config.getTime());
        builder.setMatchRule(config.getMatchRule());
        builder.setReward(config.getReward());
        builder.setFightParam(config.getFightParam());
        builder.setGuessParam(config.getGuessParam());
        return builder;
    }

    public static CrossJiuZhouPatronsData parseCrossJiuZhouPatronsData(PatronsProto.PatronsSimpleTempMsg patronsSimpleTempMsg) {
        if (patronsSimpleTempMsg == null) {
            return null;
        }
        CrossJiuZhouPatronsData crossJiuZhouPatronsData = new CrossJiuZhouPatronsData();
        crossJiuZhouPatronsData.setPatronsId(patronsSimpleTempMsg.getPatronsId());
        crossJiuZhouPatronsData.setLevel(patronsSimpleTempMsg.getLevel());
        crossJiuZhouPatronsData.setSkinId(patronsSimpleTempMsg.getSkinId());
        crossJiuZhouPatronsData.setStageLv(patronsSimpleTempMsg.getStageLv());
        crossJiuZhouPatronsData.setPromotionId(patronsSimpleTempMsg.getPromotionId());
        crossJiuZhouPatronsData.setAbility(new BigInteger(patronsSimpleTempMsg.getAbility()));
        return crossJiuZhouPatronsData;
    }

    public static PatronsProto.PatronsSimpleTempMsg.Builder parsePatronsSimpleTempMsg(CrossJiuZhouPatronsData crossJiuZhouPatronsData) {
        if (crossJiuZhouPatronsData == null) {
            return null;
        }
        PatronsProto.PatronsSimpleTempMsg.Builder builder = PatronsProto.PatronsSimpleTempMsg.newBuilder();
        builder.setPatronsId(crossJiuZhouPatronsData.getPatronsId());
        builder.setLevel(crossJiuZhouPatronsData.getLevel());
        builder.setSkinId(crossJiuZhouPatronsData.getSkinId());
        builder.setStageLv(crossJiuZhouPatronsData.getStageLv());
        builder.setPromotionId(crossJiuZhouPatronsData.getPromotionId());
        builder.setAbility(crossJiuZhouPatronsData.getAbility().toString());
        return builder;
    }

    public static JiuZhouProto.JiuZhouDeployDataMsg.Builder parseJiuZhouDeployDataMsg(CrossJiuZhouDeployData deployData, Map<Integer, CrossJiuZhouPatronsData> patronsDataMap) {
        if (deployData == null) {
            return null;
        }
        JiuZhouProto.JiuZhouDeployDataMsg.Builder deployTemp = JiuZhouProto.JiuZhouDeployDataMsg.newBuilder();
        deployTemp.setOpponentUserId(deployData.getOpponentUserId());
        deployTemp.setSkillId2(deployData.getSkillId2());
        deployTemp.setSilverBuff(deployData.getSilverBuff().toString());
        deployTemp.addAllSkillId1List(deployData.getSkillId1List());
        for (Integer patronsId : deployData.getPatronsIdList()) {
            CrossJiuZhouPatronsData patronsData = patronsDataMap.get(patronsId);
            if (patronsData == null) {
                continue;
            }
            PatronsProto.PatronsSimpleTempMsg.Builder tempMsg = parsePatronsSimpleTempMsg(patronsData);
            if (tempMsg != null) {
                deployTemp.addPatronsData(tempMsg);
            }
        }
        return deployTemp;
    }

    public static JiuZhouProto.JiuZhouGameStepDataMsg.Builder parseJiuZhouGameStepDataMsg(CrossJiuZhouGameStepData stepData) {
        if (stepData == null) {
            return null;
        }
        JiuZhouProto.JiuZhouGameStepDataMsg.Builder builder = JiuZhouProto.JiuZhouGameStepDataMsg.newBuilder();
        builder.setBattleRound(stepData.getBattleRound());
        for (CrossJiuZhouSkillEffect skillEffect : stepData.getBeforeSkillEffectList()) {
            builder.addBeforeSkillEffect(parseJiuZhouSkillEffectMsg(skillEffect));
        }
        for (CrossJiuZhouPatronsFightResult fightResult : stepData.getPatronsFightResults()) {
            builder.addFightResult(parseJiuZhouPatronsFightResult(fightResult));
        }
        for (CrossJiuZhouSkillEffect skillEffect : stepData.getAfterSkillEffectList()) {
            builder.addAfterSkillEffect(parseJiuZhouSkillEffectMsg(skillEffect));
        }
        for (CrossJiuZhouHpResult hpResult : stepData.getHpResultList()) {
            builder.addHpResult(parseJiuZhouHpResultMsg(hpResult));
        }
        for (CrossJiuZhouSkillEffect skillEffect : stepData.getAfterRoundSkillEffectList()) {
            builder.addAfterRoundSkillEffect(parseJiuZhouSkillEffectMsg(skillEffect));
        }
        return builder;
    }

    public static JiuZhouProto.JiuZhouPatronsFightResult.Builder parseJiuZhouPatronsFightResult(CrossJiuZhouPatronsFightResult fightResult) {
        if (fightResult == null) {
            return null;
        }
        JiuZhouProto.JiuZhouPatronsFightResult.Builder builder = JiuZhouProto.JiuZhouPatronsFightResult.newBuilder();
        builder.setUserId(fightResult.getUserId());
        builder.setPatronsId(fightResult.getPatronsId());
        builder.setHp(fightResult.getHp());
        builder.setAttackDamage(fightResult.getAttackDamage());
        return builder;
    }

    public static JiuZhouProto.JiuZhouHpResultMsg.Builder parseJiuZhouHpResultMsg(CrossJiuZhouHpResult hpResult) {
        if (hpResult == null) {
            return null;
        }
        JiuZhouProto.JiuZhouHpResultMsg.Builder builder = JiuZhouProto.JiuZhouHpResultMsg.newBuilder();
        builder.setUserId(hpResult.getUserId());
        builder.setType(hpResult.getType());
        builder.setHp(hpResult.getHp());
        builder.setExtraHp(hpResult.getExtraHp());
        for (CrossJiuZhouSkillEffect skillEffect : hpResult.getHpSkillEffectList()) {
            builder.addHpSkillEffect(parseJiuZhouSkillEffectMsg(skillEffect));
        }
        return builder;
    }

    public static JiuZhouProto.JiuZhouSkillEffectMsg.Builder parseJiuZhouSkillEffectMsg(CrossJiuZhouSkillEffect skillEffect) {
        if (skillEffect == null) {
            return null;
        }
        JiuZhouProto.JiuZhouSkillEffectMsg.Builder builder = JiuZhouProto.JiuZhouSkillEffectMsg.newBuilder();
        builder.setUserId(skillEffect.getUserId());
        builder.setSkillId(skillEffect.getSkillId());
        builder.addAllSkillArg(skillEffect.getSkillArgs());
        return builder;
    }

}
